import { Drawer } from 'antd';
import pageStyles from '@/common/pageLayout.less';
import { WorkflowHandTasks } from './WorkflowHandTasks';
import { useContext, useMemo } from 'react';
import { WorkflowCheckRecordContext } from '../common';
import { getPosIDs, getUserID } from '@/utils';

export const WorkFlowCheckDrawer: React.FC<IWorkflowChedkRecordAPI.IWorkFlowCheckDrawer> = ({ isShowDrawer, onClose }) => {
  /** 获取上下文 */
  const { dataDetailInfo, flowBusinessType, prefixCls, requestController } = useContext(WorkflowCheckRecordContext);

  /** 办理节点数据 */
  const checkTaskNodeInfo = useMemo(() => {
    if (dataDetailInfo?.paramObject && flowBusinessType) {
      /** 判断 */
      // const taskHandInfo: Record<string, any> = dataDetailInfo?.paramObject?.[flowBusinessType];
      // if (
      //   taskHandInfo &&
      //   taskHandInfo?.mactivitiTaskList?.length > 0 &&
      //   taskHandInfo?.mactivitiTaskList?.[0]?.assigneePositionID == getPosIDs() &&
      //   taskHandInfo?.mactivitiTaskList?.[0]?.assigneeID == getUserID()
      // ) {
      //   return taskHandInfo?.mactivitiTaskList?.[0];
      if (flowBusinessType == '100117011010') {
        return dataDetailInfo?.paramObject?.['100117011010']?.mactivitiHisProcinstList?.[0];
      } else {
        return false;
      }
    } else {
      return false;
    }
  }, [flowBusinessType, dataDetailInfo?.paramObject]);

  return (
    <Drawer
      className={pageStyles['detailDrawerDes']}
      title=""
      style={{ position: 'absolute', height: '100%', overflow: 'hidden' }}
      placement="right"
      onClose={onClose}
      open={isShowDrawer?.isShow}
      getContainer={false}
      // width={document.body?.clientWidth * 0.35}
      width={'45%'}
      headerStyle={{ padding: '16px' }}
      bodyStyle={{ padding: 0 }}
      closable={false}
      destroyOnClose={true}
    // mask={false}
    // extra={extraRender()}
    >
      <div className={`${prefixCls}flowCheckDomBox-drawerBodyBox`}>
        <WorkflowHandTasks
          // detailInfoObj={needInfo?.paramObject?.["100117011010"]?.mactivitiHisProcinstList?.[0]}
          isShowDrawer={isShowDrawer}
          detailInfoObj={checkTaskNodeInfo}
          requestController={requestController}
          reloadCallback={function (): void {
            throw new Error('Function not implemented.');
          }}
        />
      </div>
    </Drawer>
  );
};
